//
//  WACycleScrollView.m
//  assemble
//
//  Created by luqiuan on 2018/8/15.
//  Copyright © 2018年 kingsunsoft. All rights reserved.
//

#import "WACycleScrollView.h"
#import "SDCycleScrollView.h"
#import "UIImageView+WebCache.h"

@interface WACycleScrollView ()<SDCycleScrollViewDelegate>
@property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
@end

@implementation WACycleScrollView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
    }
    return self;
}

- (void)setupViews{
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, self.width, self.height) delegate:self placeholderImage:nil];
    self.cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
    self.cycleScrollView.autoScrollTimeInterval = 3;
    [self addSubview:self.cycleScrollView];
    self.cycleScrollView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
}

-(void)configImages:(NSArray *)imageList{
    NSArray *imagesURLStrings = @[
                                  @"111",
                                  @"lauch",
                                  @"111"
                                  ];
    if (imageList.count > 0) {
        imagesURLStrings = imageList;
    }
    [self.cycleScrollView setImageURLStringsGroup:imagesURLStrings];
    [self.cycleScrollView setPlaceholderImage:[UIImage imageNamed:@"lauch"]];
}

/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    if (self.clickItemBlock) {
        self.clickItemBlock(index);
    }
}

/** 图片滚动回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index{
    if (self.didScrollToIndexBlcok) {
        self.didScrollToIndexBlcok(index);
    }
}

@end
